package com.founder.client;

import java.net.URLEncoder;

import javax.servlet.http.HttpServletRequest;

import com.baomidou.kisso.SSOConfig;

/**
 * @author 作者 E-mail:
 * @date 创建时间：2017年12月27日 下午3:46:26
 * @version 1.0
 * @parameter
 * @since
 * @return
 */
public class ReturnUrlUtil {
	 
	
	public static String getAhfzbdReturnUrl(HttpServletRequest request) throws Throwable {
		StringBuffer url = new StringBuffer(request.getScheme());
		// 请求协议 http,https
		url.append("://");
		url.append(request.getHeader("host"));// 请求服务器
		url.append(request.getRequestURI());// 工程名
 		String returnUrl = url.substring(0, url.lastIndexOf("ahfounderbd"));
		return URLEncoder.encode(returnUrl, "UTF-8");
	}

	
	public static String getAhfzbdUrl(HttpServletRequest request) throws Throwable {
		StringBuffer url = new StringBuffer(request.getScheme());
		// 请求协议 http,https
		url.append("://");
		url.append(request.getHeader("host"));// 请求服务器
		url.append(request.getRequestURI());// 工程名
 		String returnUrl = url.substring(0, url.lastIndexOf("/ahfounderbd"));
		return returnUrl;
	}

	public static String getUrl(HttpServletRequest request) throws Throwable {
		StringBuffer url = new StringBuffer(request.getScheme());
		// 请求协议 http,https
		url.append("://");
		url.append(request.getHeader("host"));// 请求服务器
		url.append(request.getRequestURI());// 工程名
  		String returnUrl = url.substring(0, url.lastIndexOf("/"));
		return returnUrl;
	}

	public static String getReturnUrl(HttpServletRequest request) throws Throwable {
		String url = getUrl(request)+"/";
		return URLEncoder.encode(url, "UTF-8");
	}
	
	
	public static String getConfigUrl(String defalutURL, String configUrlKey) {
		String str = SSOConfig.getSSOProperties().get(configUrlKey);
		return str == null || "".equals(str) ? defalutURL : str;
	}
}
